package com.example.demo.controller;


import cn.hutool.db.Page;
import com.example.demo.entity.user;
import com.example.demo.service.superuserserviceInter;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("superuser")
public class superusercontroller {
    @Autowired
    superuserserviceInter superuserdao;

    @RequestMapping("serchroot")
    public int getauthorityid(user u) {
        user user = new user();
        user = superuserdao.getauthorityid(u);
        System.out.println(user.getAuthorityid());
        return user.getAuthorityid();
    }

    @RequestMapping("/display")
    public PageInfo<user> dispaly(@RequestParam(value = "pagenum", required = false, defaultValue = "1")Integer pagenum,
                                  @RequestParam(value = "pagesize", required = false, defaultValue = "5")Integer pagesize,
                                  Model model) {
        PageInfo<user> userpageinfo = superuserdao.getusers(pagenum, pagesize);
        model.addAttribute("userpageinfo", userpageinfo);

        return userpageinfo;
    }

    @RequestMapping("search")
    public user searchuser(user u) {
        return superuserdao.searchuser(u);
    }

    @RequestMapping("update")
    public int update(user u) {
        return superuserdao.updateuser(u);
    }
}
